use std::env;
use std::path::PathBuf;

fn main(){
    let arc_ui_x_dir = PathBuf::from(env::var("ArkUI_X_HOME").expect("请设置 ArkUI_X_HOME 环境变量"));
    let mut oh_dir = PathBuf::from(env::var("OpenHarmony_HOME").expect("请设置 OpenHarmony_HOME 环境变量"));
    oh_dir = oh_dir.join("10").join("native").join("sysroot").join("usr");

    let ui_dir = arc_ui_x_dir.join("10").join("arkui-x").join("engine").join("lib");
    let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
    let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
    // let ui_include_dir = ui_dir.join("include");
    // let header = ui_include_dir.join("napi").join("native_api.h");

    if target_os.as_str() == "android"{
        let dir_name = match target_arch.as_str() {
            "aarch64"=> "android-arm64-release",
            "arm"=> "android-arm-release",
            "x86_64"=> "android-x86_64",
            _=> panic!("{} 不支持", target_arch),
        };
        let lib_dir = ui_dir.join("arkui").join(dir_name);
        println!("cargo:rustc-link-search={}", lib_dir.display());
        println!("cargo:rustc-link-lib=arkui_android");
    }

    if target_os.as_str() == "ohos" || target_os.as_str() == "android" ||  target_os.as_str() == "ios"
    {
        let dir_name = format!("{}-linux-ohos", target_arch);
        let lib_dir = oh_dir.join("lib").join(dir_name);
        println!("cargo:rustc-link-search={}", lib_dir.display());
        println!("cargo:rustc-link-lib=ace_napi.z");
    }


    // The bindgen::Builder is the main entry point
    // to bindgen, and lets you build up options for
    // the resulting bindings.
    // let bindings = bindgen::Builder::default()
    //     // The input header we would like to generate
    //     // bindings for.
    //     .header(header.display().to_string())
    //     .clang_arg(format!("-I{}", ui_include_dir.display()))
    //     // Finish the builder and generate the bindings.
    //     .generate()
    //     // Unwrap the Result and panic on failure.
    //     .expect("Unable to generate bindings");
    //
    // // Write the bindings to the $OUT_DIR/bindings.rs file.
    // let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
    // bindings
    //     .write_to_file(out_path.join("bindings.rs"))
    //     .expect("Couldn't write bindings!");


}